package com.java46.service;

import com.java46.bean.Personnel;
import com.java46.exception.MyException;
import com.java46.mapper.PersonnelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class PersonnelService {

    //从spring得mapper接口
    @Autowired
    private PersonnelMapper personnelMapper;

    public List<Personnel> getAllPersonnel() throws MyException {

        List<Personnel> personnels;
        try {
            personnels = personnelMapper.selectAll();
        }catch (Exception e){
            e.printStackTrace();
            throw new MyException("没有查询到相关数据");
        }
        return personnels;
    }

    public void addPersonnel(Personnel personnel){
        personnelMapper.insert(personnel);
    }
}

